package com.bms.common;

import java.io.IOException;
import java.util.Date;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

import com.bms.utils.DateUtil;

/**
 * 针对Date类型的JSON数据处理：将返回的JSON格式中，日期类型转化为字符串类型，用于前台显示
 * <pre>相应注解：@JsonSerialize(using = CustomDateSerializer.class)</pre>
 * @author Lan
 */
public class JsonDateSerializer extends JsonSerializer<Date> {

	@Override
	public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
			throws IOException, JsonProcessingException {
		if(value != null){
			jgen.writeString(DateUtil.formatDate(value, DateUtil.LONG_DATE));
		}
	}


}
